package com.htgd.gardenexpo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.GeConHealthy;
import com.htgd.gardenexpo.dao.GeConHealthyMapper;
import com.htgd.gardenexpo.page.HealthyQuery;
import com.htgd.gardenexpo.service.GeBaseDictService;
import com.htgd.gardenexpo.service.GeConHealthyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.htgd.gardenexpo.service.WxUserCollectService;
import com.htgd.gardenexpo.utils.TokenUtil;
import com.htgd.gardenexpo.vo.GeConHealthyVO;
import com.htgd.gardenexpo.vo.GeConSportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 健康科普 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-26
 */
@Service
public class GeConHealthyServiceImpl extends ServiceImpl<GeConHealthyMapper, GeConHealthy> implements GeConHealthyService {

    @Autowired
    private GeConHealthyMapper geConHealthyMapper;

    @Autowired
    private GeBaseDictService geBaseDictService;

    @Autowired
    private WxUserCollectService wxUserCollectService;

    @Override
    public PageInfo<GeConHealthyVO> pageList(HealthyQuery healthyQuery, HttpServletRequest request) {
        PageHelper.startPage(healthyQuery.getPageNum(), healthyQuery.getPageSize());
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        List<GeConHealthyVO> list= geConHealthyMapper.pageList(healthyQuery);
        for (GeConHealthyVO geConHealthyVO : list) {
            if(geConHealthyVO.getStatus()!=null){
                geConHealthyVO.setStatusText(geBaseDictService.getStatusText(String.valueOf(geConHealthyVO.getStatus())));
            }
            if(geConHealthyVO.getIsTop()!=null){
                geConHealthyVO.setIsTopText(geBaseDictService.getTopText(String.valueOf(geConHealthyVO.getIsTop())));
            }
            Boolean collect = wxUserCollectService.isLike(openId, geConHealthyVO.getId(),"healthy");
            if (collect) {
                geConHealthyVO.setIsLike(true);
            }else{
                geConHealthyVO.setIsLike(false);
            }
        }
        return new PageInfo<>(list);
    }
}
